
//
//  GDFMomentDetiallViewController.m
//  GlobalDeliciousFood
//
//  Created by 赵洁 on 16/1/11.
//  Copyright © 2016年 com.mjykj.www. All rights reserved.
//

#import "GDFMomentDetiallViewController.h"
#import "GDFMomentDetiallUPTableViewCell.h"
#import "GDFMomentDetiallDownTableViewCell.h"
#import "GDFMomentDetiallModle.h"
@interface GDFMomentDetiallViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView *DtableView;
@property(nonatomic,strong)NSMutableArray *detiallArray;


@end

@implementation GDFMomentDetiallViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    _DtableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:(UITableViewStyleGrouped)];
    _DtableView.delegate = self;
    _DtableView.dataSource = self;
    [_DtableView registerClass:[GDFMomentDetiallUPTableViewCell class] forCellReuseIdentifier:@"upCell"];
    [_DtableView registerClass:[GDFMomentDetiallDownTableViewCell class] forCellReuseIdentifier:@"downCell"];
    [self.view addSubview:_DtableView];
    [self setUpdata];

}

-(void)setUpdata
{
    NSString *str = @"8c%3Abe%3Abe%3A71%3Acb%3A1d";
    NSString *string = [NSString stringWithFormat:@"http://www.youyuwei.com/api/foodcamera?oauth_version=1.0&oauth_nonce=96db6694-8525-4bf0-91d4-d788985545b3&oauth_consumer_key=5&device_type=android&screen_width=1080&list=Topic&device_id=%@&ver=3&ywsdk_ver=20140507&sys_ver=4.4.4&ver_code=21&channel_id=baidu&id=%@&oauth_signature=%@&x_auth_mode=client_auth&device_token=AuW2jEg1O9f1alTq8V-SVbpyWh8WsL5ixRbT1Say5rL0&oauth_signature_method=HMAC-SHA1&oauth_token=0_9837387abc33331ab&open_udid=7IJD8h7hMKBuCnJsyYdfWN508tY%3D&app_ver=2.8&app_code=com.yuwei.android&oauth_timestamp=1452485166&screen_height=1920",str,_model.ID,str];
    
    //NSString* strAfterDecodeByUTF8AndURI = [@"%E4%B8%AD%E5%9B%BD" stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSString *str1 = [@"%E4%B8%AD%E5%9B%BD" stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSLog(@"%@",str1);
 
    [GDFRequestManager requestWithUrl:string parmDic:nil method:GET1 succeedWithData:^(NSData *data) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableLeaves) error:nil];
        NSDictionary *dataDic = dic[@"data"];
        NSArray *listArray = dataDic[@"list"];
        _detiallArray = [NSMutableArray array];
        for (NSDictionary *oneDic in listArray) {
            GDFMomentDetiallModle *Dmodel = [[GDFMomentDetiallModle alloc]init];
            [Dmodel setValuesForKeysWithDictionary:oneDic];
            [_detiallArray addObject:Dmodel];
        }
        [_DtableView reloadData];
    } failedWithError:^(NSError *connectionError) {
        
    }];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _detiallArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row % 2 == 0) {
        GDFMomentDetiallUPTableViewCell *upCell = [tableView dequeueReusableCellWithIdentifier:@"upCell"];
        tableView.rowHeight = 80;
        GDFMomentDetiallModle *model = _detiallArray[indexPath.row];
        upCell.model = model;
        return upCell;
    }else
    {
        GDFMomentDetiallDownTableViewCell *downCell = [tableView dequeueReusableCellWithIdentifier:@"downCell"];
        GDFMomentDetiallModle *model = _detiallArray[indexPath.row];
        downCell.model = model;
        tableView.rowHeight = 300;
        
        return downCell;
    }
        
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
